import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:series_play/comm/base/base_state.dart';
import 'package:series_play/generated/assets.dart';
import 'package:series_play/widget/app_color.dart';
import 'package:series_play/widget/app_image.dart';
import 'package:series_play/widget/app_refresh_view.dart';
import 'package:series_play/widget/app_text.dart';

import 'controller/binge_watch_controller.dart';
import 'controller/watch_history_controller.dart';

class WatchHistoryPage extends StatefulWidget {
  const WatchHistoryPage(this.controller, {super.key});

  final BingeWatchController controller;

  @override
  State<WatchHistoryPage> createState() => _WatchHistoryPageState();
}

class _WatchHistoryPageState
    extends BaseState<WatchHistoryPage> {
  BingeWatchController get _parentController => widget.controller;
  WatchHistoryController get mController => widget.controller.watchHistoryController;

  @override
  Widget buildPage(BuildContext context) {
    return AppRefreshListView(
      listController: mController,
      itemBuilder: (context, index) {
        return Container(
          padding: const EdgeInsets.symmetric(horizontal: 16).w,
          height: 100.w,
          child: Row(
            children: [
              Obx(() {
                return Visibility(
                  visible: _parentController.isEditModel.value,
                  child: Padding(
                    padding: const EdgeInsets.only(right: 16).w,
                    child: AppImage.assetsWith15(Assets.imagesIcCheckboxNormal),
                  ),
                );
              }),
              AppImage.round(
                mController.dataList[index],
                width: 76,
                height: 100,
              ),

              10.horizontalSpace,
              Expanded(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    AppText(
                      '悬崖下的妻子悬崖下的妻子',
                      maxLines: 2,
                      fontWeight: FontWeight.bold,
                    ),
                    const Spacer(),
                    Row(
                      children: [
                        AppText(
                          '第一集',
                          fontSize: 13,
                          color: AppColor.seriesSortCount,
                        ),
                        AppText('/100集', fontSize: 13),
                      ],
                    ),
                    const Spacer(),
                    AppText('1小时前', fontSize: 12, color: AppColor.white_40),
                  ],
                ),
              ),
              16.horizontalSpace,
              AppImage(Assets.imagesIcWatchHistoryTvNormal, size: 20),
            ],
          ),
        );
      },
      separatorBuilder: (context, index) {
        return 12.verticalSpace;
      },
      onRefresh: mController.onRefreshing,
      onLoad: mController.onLoadingMore,
    );
  }

  @override
  bool hideAppbar() {
    return true;
  }

  @override
  Color getBackgroundColor() {
    return Colors.transparent;
  }

  @override
  bool get wantKeepAlive => true;
}
